package org.blackjuly.sign.service;

import org.blackjuly.sign.data.DataBean;
import org.blackjuly.sign.data.DataTrimmer;
import org.blackjuly.sign.entity.Comment;

public class CommentService extends BaseService {
	/**
	 * 添加评论
	 */
	public void comment(Comment comment, String from) throws Exception {
		DataBean<Comment> dataBean = new DataBean<>(conn, from, "id");
		dataBean.doSave(comment);
	}

	/**
	 * 查看评论
	 */
	public Comment seeComment(String from, long id) throws Exception {
		DataBean dataBean = new DataBean(this.conn, from, "id");
		dataBean.setEntityClass(Comment.class);
		return (Comment) dataBean.doSelect(Long.valueOf(id));
	}

	/**
	 * 查找最大的id
	 */
	public Long findBestId(String from) throws Exception {
		String sql = "select max(id) as maxid from " + from;
		DataTrimmer dt = new DataTrimmer(this.conn);
		return (Long)dt.selectOne(sql).get("maxid");
	}
}